<?php

/**
 * File upload validator
 *
 */
class Application_Form_FileValidator extends Zend_Validate_Abstract
{
    protected $_upload_dir=Application_Model_File::UPLOAD_DIR;
    
    protected $_messageTemplates = array(
        'fileExists' => "File '%value%' is already exists"
    );
    
    /**
     * Validate interface isValid function
     *
     * @param string $value
     * @return bool
     */
    public function isValid($value,$context=null)
    {
        if (empty($value)) return false;

        $this->_setValue($value);
        
        if (file_exists(ROOT_DIR.'/'.$this->_upload_dir.'/'.$context['name'])) 
        {
            $this->_error('fileExists');
            return false;
        }

        return true;
    }
}